package com.example.service.impl;

import com.example.mapper.QuestionMapper;
import com.example.pojo.Question;
import com.example.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public List<Question> getAllQuestions() {
        return questionMapper.getAllQuestions();
    }

    @Override
    public Question getQuestionById(Integer id) {
        return questionMapper.getQuestionById(id);
    }

    @Override
    public void saveQuestion(Question question) {
        questionMapper.insertQuestion(question);
    }

    @Override
    public boolean checkAnswer(Integer id, Integer answerIndex) {
        Integer correctAnswerIndex = questionMapper.getCorrectAnswerIndex(id);
        return correctAnswerIndex == answerIndex; // 判断用户选择的答案是否正确
    }
}
